#ifndef _TIO_GRIPPER_H_
#define _TIO_GRIPPER_H_
#ifdef __cplusplus
extern "C" {
#endif
#define MAX_TIO_SIG_NUM 8

typedef enum
{
    GRIPPER_WAITING_TO_SEND_NORMAL = 0,
    GRIPPER_WAITING_TO_SEND_ERROR = 1,
    GRIPPER_WAITING_REC_NORMAL = 2,
    GRIPPER_WAITING_REC_ERROR = 3
} GripperState;

typedef struct
{
    char sigName[128];  // name to identify the signal
    unsigned char chnId;
    unsigned int slaveId;  // slave id
    unsigned int type;     // function code, 0x01: read coil, 0x02: discete inputs; 0x03: holding register; 0x04: input register
    unsigned int addr;     // register address, only support reading one register once
    unsigned int value;
    float freq;                 // <=0 for once, >0 for cycling query
    int count;                  // 信号发送数量，保证队列中最多有1条
    int prog_state_when_error;  // 错误发生时，程序是否停止，1 for 停止
    GripperState commu_state;   // 0 for 未发送， 1 for 发送中， -1 for 发送失败
} GripperStateUnit;

extern GripperStateUnit* tio_gripper_list_signal();
extern GripperStateUnit* checkGripperSigByName(const char* name);
extern int tio_gripper_has_signal();
extern int tio_gripper_add_signal(const char* name, int chnId, int slaveId, int type, int addr);
extern int tio_gripper_del_signal(const char* name);
extern int tio_gripper_clr_signal(int chnId);
extern int tio_gripper_update_signal(const char* name, float freq, const int* chn_mode);
extern int tio_gripper_send(int chnId, unsigned char data[32], unsigned int len);
extern void checkSignalUpdate(const int* chn_enable, const int* chn_mode);
extern void tio_gripper_reset_send_state();
extern int tio_gripper_set_signal_prog_stat(const char* name, int prog_stat);
#ifdef __cplusplus
}
#endif
#endif